package org.example.springwebmvc.mapper;

import org.apache.ibatis.annotations.*;
import org.example.springwebmvc.model.MessageInfo;

import java.util.List;

/**
 * @ClassName MessageInfoMapper
 * @Description
 * @Author ZJX
 * @Date 2024/8/26 19:18
 * @Version 1.0
 */
@Mapper
public interface MessageInfoMapper {
    // 发布留言
    @Insert("INSERT INTO message_info (`from`, `to`, message, create_time, update_time, delete_flag) VALUES (#{from}, #{to}, #{say}, #{createTime}, #{updateTime}, #{deleteFlag})")
    Integer insertMessage(MessageInfo messageInfo);

    // 获取留言
    @Select("SELECT `from`, `to`, message, create_time, update_time, delete_flag FROM message_info WHERE delete_flag = 0")
    @Results({
            @Result(property = "say", column = "message"), // property 对应着 java对象字段   column 对应着数据库属性
            @Result(property = "createTime", column = "create_time"),
            @Result(property = "updateTime", column = "update_time"),
            @Result(property = "deleteFlag", column = "delete_flag")
    })
    List<MessageInfo> selectAllList();
}
